package gui;


import java.sql.Time;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.swing.JOptionPane;
import modelo.TableModelReclamaciones;
import persistencia.ReclamacionesDAO;
import pojos.Reclamacion;

public class PanelReclamaciones extends javax.swing.JPanel {
  
    int idReclamacion;//autoincremental
    int codEmpleado;
    int codPaciente;
    String descripcion;
    ReclamacionesDAO dao = new ReclamacionesDAO();
    List<String> nombreColumnas = new LinkedList();

    public PanelReclamaciones(VentanaPrincipal ventana) {
        initComponents();   
        nombreColumnas.add("idReclamacion");
        nombreColumnas.add("codEmpleado");
        nombreColumnas.add("codPaciente");
        nombreColumnas.add("Descripcion");
        Buscar();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPfiltros = new javax.swing.JPanel();
        choiseIdReclamacion = new javax.swing.JCheckBox();
        fieldReclamacion = new javax.swing.JTextField();
        choiseDescripcion = new javax.swing.JCheckBox();
        fieldDescripcion = new javax.swing.JTextField();
        btnAgregar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        btnModificar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabla = new javax.swing.JTable();
        btnConsultar = new javax.swing.JButton();

        jPfiltros.setBorder(javax.swing.BorderFactory.createTitledBorder("Filtros de Búsqueda"));
        jPfiltros.setLayout(new java.awt.GridLayout(4, 2));

        choiseIdReclamacion.setText("idReclamacion");
        jPfiltros.add(choiseIdReclamacion);
        jPfiltros.add(fieldReclamacion);

        choiseDescripcion.setText("descripcion");
        jPfiltros.add(choiseDescripcion);
        jPfiltros.add(fieldDescripcion);

        btnAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/ico_plus.png"))); // NOI18N
        btnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarActionPerformed(evt);
            }
        });

        btnEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/ico_bin.png"))); // NOI18N
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });

        btnModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/ico_edit1.png"))); // NOI18N
        btnModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificarActionPerformed(evt);
            }
        });

        jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jPanel1.setLayout(new java.awt.GridLayout(1, 0));

        tabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tabla);

        jPanel1.add(jScrollPane1);

        btnConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/ico_find.png"))); // NOI18N
        btnConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConsultarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(237, 237, 237)
                        .addComponent(jPfiltros, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 772, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btnAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(btnModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(btnConsultar)
                                .addGap(18, 18, 18)
                                .addComponent(btnEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(btnEliminar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnModificar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnAgregar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(btnConsultar))
                .addGap(41, 41, 41)
                .addComponent(jPfiltros, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
        JDialogReclamaciones dialogoAgregar=new JDialogReclamaciones(1,this);
        dialogoAgregar.setVisible(true);
    }//GEN-LAST:event_btnAgregarActionPerformed

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        JDialogReclamaciones dialogoEliminar=new JDialogReclamaciones(2,this);
        dialogoEliminar.setVisible(true);
    }//GEN-LAST:event_btnEliminarActionPerformed

    private void btnModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarActionPerformed
        JDialogReclamaciones dialogoModificar=new JDialogReclamaciones(3,this);
        dialogoModificar.setVisible(true);
    }//GEN-LAST:event_btnModificarActionPerformed

    private void btnConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConsultarActionPerformed
        try {
            Buscar();
        } catch (Exception e) {
            System.out.println(e);
            JOptionPane.showMessageDialog(this, "No existen reclamaciones");
        }
    }//GEN-LAST:event_btnConsultarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregar;
    private javax.swing.JButton btnConsultar;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnModificar;
    private javax.swing.JCheckBox choiseDescripcion;
    private javax.swing.JCheckBox choiseIdReclamacion;
    private javax.swing.JTextField fieldDescripcion;
    private javax.swing.JTextField fieldReclamacion;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPfiltros;
    private javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JTable tabla;
    // End of variables declaration//GEN-END:variables

    public void Buscar() {
        List<Reclamacion> listaReclamaciones;
        boolean tickReclamacion = this.choiseIdReclamacion.isSelected();
        boolean tickDescripcion = this.choiseDescripcion.isSelected();        
        String idReclamacion;
        String descripcion; 
        if (tickReclamacion==true) {
            idReclamacion = this.fieldReclamacion.getText();
        }else{
            idReclamacion="%";
        }
        if (tickDescripcion==true) {
            descripcion = this.fieldDescripcion.getText();
        }else{
            descripcion="%";
        }
            listaReclamaciones= this.dao.obtenListaReclamacion(idReclamacion, descripcion);        

        this.tabla.setModel(new TableModelReclamaciones(listaReclamaciones, nombreColumnas));
    }
}
